//Mark O Meara
//08332240
//CS2031 - Assignment 2
//Due: 12/3/10
import tcdIO.*;

public class Sandbox {

	/*
	 * Main method that creates a buffer, fills the buffer with content, 
	 * creates 2 channels to connect a sender and a receiver and then
	 * creates a Sender and a Receiver thread.
	 */
	public static void main(String[] args) {
		Terminal terminal1 = new Terminal("Sandbox");
		Thread rec,sen;
		
		terminal1.println("Start of Sandbox");

		try {
			byte[] buffer= new byte[7500];			// fill message with random data
			//Filling message with data:
			for(int i=0; i<buffer.length; i++) {
				buffer[i]= (byte) (i % 255); 
			}
			//Makes the last two bytes into 1's
			buffer[buffer.length-1]= (byte) 255;
			buffer[buffer.length-2]= (byte) 255;

			//Creating two channels to connect sending and receiver
			Channel channel1 = new Channel();
			Channel channel2 = new Channel();
			
			rec = new Thread(new Receiver(channel1, channel2), "Receiver");;
			sen = new Thread(new Sender(channel2, channel1, buffer), "Sender");
		
			rec.start();
			sen.start();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		
		terminal1.println("End of Sandbox");
	}	
}